package com.eastcom.mystope.daemon.core.process;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import com.eastcom.mystope.common.util.SpringContextProvider;
import com.eastcom.mystope.daemon.config.ExternConfigPath;
import com.eastcom.mystope.daemon.context.ServerContext;
import com.eastcom.mystope.daemon.extern.db.process.DbTaskInitProcess;
import com.eastcom.mystope.daemon.extern.file.ftp.process.FileFtpTaskInitProcess;
import com.eastcom.mystope.daemon.extern.file.parse.txt.process.FileParseTaskInitProcess;
import com.eastcom.mystope.daemon.extern.shell.process.ShellTaskInitProcess;
@Component("serverInitProcess")
public class ServerInitProcess {
	private static Log logger = LogFactory.getLog(ServerInitProcess.class);
	@Resource(name = "threadPool")
	private ThreadPoolTaskExecutor threadPoolTaskExecutor;
	private ShellTaskInitProcess shellTaskInitProcess;
	private DbTaskInitProcess dbTaskInitProcess;
	private FileFtpTaskInitProcess fileFtpTaskInitProcess;
	private FileParseTaskInitProcess txtFileParseTaskInitProcess;
	private com.eastcom.mystope.daemon.extern.file.parse.csv.process.FileParseTaskInitProcess csvFileParseTaskInitProcess;
	private com.eastcom.mystope.daemon.extern.file.parse.excel.process.FileParseTaskInitProcess excelFileParseTaskInitProcess;
	public void init(){
		threadPoolTaskExecutor.execute(new Runnable() {

			@Override
			public void run() {
				ExternConfigPath config = ServerContext.serverPath.getOtherConfigPath();
				logger.debug(config);
				shellTaskInitProcess = SpringContextProvider.getBean("shellTaskInitProcess");
				shellTaskInitProcess.init(config.getShellTask());
				fileFtpTaskInitProcess = SpringContextProvider.getBean("fileFtpTaskInitProcess");
				fileFtpTaskInitProcess.init(config.getTxtFileTask());
				fileFtpTaskInitProcess.init(config.getCsvFileTask());
				fileFtpTaskInitProcess.init(config.getExcelFileTask());
				txtFileParseTaskInitProcess = SpringContextProvider.getBean("txtFileParseTaskInitProcess");
				txtFileParseTaskInitProcess.init(config.getTxtFileTask());
				
				csvFileParseTaskInitProcess = SpringContextProvider.getBean("csvFileParseTaskInitProcess");
				csvFileParseTaskInitProcess.init(config.getCsvFileTask());
				
				excelFileParseTaskInitProcess = SpringContextProvider.getBean("excelFileParseTaskInitProcess");
				excelFileParseTaskInitProcess.init(config.getExcelFileTask());
				
				dbTaskInitProcess = SpringContextProvider.getBean("dbTaskInitProcess");
				dbTaskInitProcess.init(config.getDbTask());
			}
		});
	}
	
}
